package com.hzj.recipe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hzj.recipe.entity.Step;
import com.hzj.recipe.entity.Step;
import com.hzj.recipe.mapper.StepMapper;
import com.hzj.recipe.service.StepService;
import com.hzj.recipe.mapper.StepMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
* @author 蜗牛菌
* @description 针对表【step(步骤表)】的数据库操作Service实现
* @createDate 2024-01-04 10:49:47
*/
@Service
public class StepServiceImpl extends ServiceImpl<StepMapper, Step>
    implements StepService{

    @Autowired
    private StepMapper stepMapper;

    @Override
    public Object listAll(Integer index, Integer size, Step step) {
        //默认第一页开始，每页5条
        if(index == null ||index==0){
            index=1;
        }
        if(size==null||size==0){
            size=5;
        }
        Page<Step> pageInfo = new Page(index, size);
        LambdaQueryWrapper<Step> lambdaQueryWrapper = new LambdaQueryWrapper();
        if (step.getStepId() != null && step.getStepId() != 0 && !Objects.equals(step.getStepId(), "")) {
            lambdaQueryWrapper.eq(Step::getStepId, step.getStepId());
        }
        if (step.getRecipeId() != null && step.getRecipeId() != 0 && !Objects.equals(step.getRecipeId(), "")) {
            lambdaQueryWrapper.eq(Step::getRecipeId, step.getRecipeId());
        }
        if ((step.getStepsContent()!=null) && !Objects.equals(step.getStepsContent(), "")) {
            lambdaQueryWrapper.like(Step::getStepsContent, step.getStepsContent());
        }
        if (step.getStepsSort() != null && step.getStepsSort() != 0 && !Objects.equals(step.getStepsSort(), "")) {
            lambdaQueryWrapper.eq(Step::getStepsSort, step.getStepsSort());
        }

        Page<Step> stepPage = stepMapper.selectPage(pageInfo, lambdaQueryWrapper);
        return stepPage;
    }
}




